home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / librw / RWBitVec.z / RWBitVec
Encoding:
Text File  |  2002-10-03  |  17.7 KB  |  463 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))                                                  RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWBitVec - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/bitvec.h>
  13.  
  14.  
  15.  
  16.               RWBitVec v;
  17.  
  18.  
  19.  
  20.  
  21. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  22.      Class RRRRWWWWBBBBiiiittttVVVVeeeecccc is a bitvector whose length can be changed at run time.
  23.      Because this requires an extra level of indirection, this makes it
  24.      slightly less efficient than classes RRRRWWWWGGGGBBBBiiiittttVVVVeeeecccc((((ssssiiiizzzzeeee)))) or RRRRWWWWTTTTBBBBiiiittttVVVVeeeecccc<<<<ssssiiiizzzzeeee>>>>,
  25.      whose lengths are fixed at compile time.
  26.  
  27. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  28.      Simple
  29.  
  30. EEEExxxxaaaammmmpppplllleeee
  31.               #include <rw/bitvec.h>
  32.           #include <rw/rstream.h>
  33.           main(){
  34.              // Allocate a vector with 20 bits, set to TRUE:
  35.              RWBitVec av(20, TRUE);
  36.              av(2) = FALSE;     // Turn bit 2 off
  37.              av.clearBit(7);    // Turn bit 7 off
  38.              av.setBit(2);      // Turn bit 2 back on
  39.              for(int i=11; i<=14; i++) av(i) = FALSE;
  40.              cout << av << endl;    // Print the vector out
  41.           }
  42.  
  43.  
  44.      PPPPrrrrooooggggrrrraaaammmm oooouuuuttttppppuuuutttt::::
  45.  
  46.                  [
  47.  
  48.  
  49.  
  50.                  1 1 1 1 1 1 1 0 1 1 1 0 0 0 0 1 1 1 1 1
  51.  
  52. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
  53.         ]
  54.  
  55.  
  56.  
  57.               RWBitVec();
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))                                                  RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.      Construct a zero lengthed (null) vector.
  75.  
  76.               RWBitVec(size_t N);
  77.  
  78.  
  79.      Construct a vector with NNNN bits.  The initial value of the bits is
  80.      undefined.
  81.  
  82.               RWBitVec(size_t N, RWBoolean initVal);
  83.  
  84.  
  85.      Construct a vector with NNNN bits, each set to the Boolean value iiiinnnniiiittttVVVVaaaallll.
  86.  
  87.               RWBitVec(const RWByte* bp, size_t N);
  88.  
  89.  
  90.      Construct a vector with NNNN bits, initialized to the data in the array of
  91.      bytes pointed to by bbbbpppp.  This array must be at least long enough to
  92.      contain NNNN bits.  The identifier RRRRWWWWBBBByyyytttteeee is a typedef for an uuuunnnnssssiiiiggggnnnneeeedddd cccchhhhaaaarrrr.
  93.  
  94.               RWBitVec(const RWBitVec& v);
  95.  
  96.  
  97.      Copy constructor.  Uses value semantics -- the constructed vector will be
  98.      a copy of vvvv.
  99.  
  100.               ~RWBitVec();
  101.  
  102.  
  103.      The destructor.  Releases any allocated memory.
  104.  
  105. AAAAssssssssiiiiggggnnnnmmmmeeeennnntttt OOOOppppeeeerrrraaaattttoooorrrrssss
  106.               RWBitVec&
  107.           ooooppppeeeerrrraaaattttoooorrrr====(const RWBitVec& v);
  108.  
  109.  
  110.      Assignment operator.  Value semantics are used -- self will be a copy of
  111.      vvvv.
  112.  
  113.               RWBitVec&
  114.           ooooppppeeeerrrraaaattttoooorrrr====(RWBoolean b);
  115.  
  116.  
  117.      Assignment operator.  Sets every bit in self to the boolean value bbbb.
  118.  
  119.               RWBitVec&
  120.           ooooppppeeeerrrraaaattttoooorrrr&&&&====(const RWBitVec& v);
  121.           RWBitVec&
  122.           ooooppppeeeerrrraaaattttoooorrrr^^^^====(const RWBitVec& v);
  123.           RWBitVec&
  124.           ooooppppeeeerrrraaaattttoooorrrr||||====(const RWBitVec& v);
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))                                                  RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.      Logical assignments.  Set each element of self to the logical AND, XOR,
  141.      or OR, respectively, of self and the corresponding bit in vvvv.  Self and vvvv
  142.      must have the same number of elements (iiii....eeee...., be conformal) or an
  143.      exception of type RRRRWWWWIIIInnnntttteeeerrrrnnnnaaaallllEEEErrrrrrrr will occur.
  144.  
  145. IIIInnnnddddeeeexxxxiiiinnnngggg OOOOppppeeeerrrraaaattttoooorrrrssss
  146.               RWBitRef
  147.           ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i);
  148.  
  149.  
  150.      Returns a reference to bit iiii of self.  A helper class, RRRRWWWWBBBBiiiittttRRRReeeeffff, is used.
  151.      The result can be used as an lvalue.  The index iiii must be between 0 and
  152.      the length of the vector less one.  Bounds checking is performed.  If the
  153.      index is out of range, then an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrr will occur.
  154.  
  155.               RWBitRef
  156.           ooooppppeeeerrrraaaattttoooorrrr(((())))(size_t i);
  157.  
  158.  
  159.      Returns a reference to bit iiii of self.  A helper class, RRRRWWWWBBBBiiiittttRRRReeeeffff, is used.
  160.      The result can be used as an lvalue.  The index iiii must be between 0 and
  161.      the length of the vector less one.  Bounds checking is performed only if
  162.      the preprocessor macro RRRRWWWWBBBBOOOOUUUUNNNNDDDDSSSS____CCCCHHHHEEEECCCCKKKK has been defined before including
  163.      the header file <<<<rrrrwwww////bbbbiiiittttvvvveeeecccc....hhhh>>>>.  If so, and if the index is out of range,
  164.      then an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrr will occur.
  165.  
  166.               RWBoolean
  167.           ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i) const;
  168.  
  169.  
  170.      Returns the boolean value of bit iiii.  The result cannot be used as an
  171.      lvalue.  The index iiii must be between 0 and the length of the vector less
  172.      one.  Bounds checking is performed.  If the index is out of range, then
  173.      an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrr will occur.
  174.  
  175.               RWBoolean
  176.           ooooppppeeeerrrraaaattttoooorrrr(((())))(size_t i) const;
  177.  
  178.  
  179.      Returns the boolean value of bit iiii.  The result cannot be used as an
  180.      lvalue.  The index iiii must be between 0 and the length of the vector less
  181.      one.  Bounds checking is performed only if the preprocessor macro
  182.      RRRRWWWWBBBBOOOOUUUUNNNNDDDDSSSS____CCCCHHHHEEEECCCCKKKK has been defined before including the header file
  183.      <<<<rrrrwwww////bbbbiiiittttvvvveeeecccc....hhhh>>>>.  If so, and if the index is out of range, then an
  184.      exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrr will occur.
  185.  
  186. LLLLooooggggiiiiccccaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss
  187.               RWBoolean
  188.           ooooppppeeeerrrraaaattttoooorrrr========(const RWBitVec& u) const;
  189.  
  190.  
  191.      Returns TTTTRRRRUUUUEEEE if self and vvvv have the same length and if each bit of self
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))                                                  RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.      is set to the same value as the corresponding bit in vvvv.  Otherwise,
  207.      returns FFFFAAAALLLLSSSSEEEE.
  208.  
  209.               RWBoolean
  210.           ooooppppeeeerrrraaaattttoooorrrr!!!!====(const RWBitVec& u) const;
  211.  
  212.  
  213.      Returns FFFFAAAALLLLSSSSEEEE if self and vvvv have the same length and if each bit of self
  214.      is set to the same value as the corresponding bit in vvvv.  Otherwise,
  215.      returns TTTTRRRRUUUUEEEE.
  216.  
  217.               RWBoolean
  218.           ooooppppeeeerrrraaaattttoooorrrr========(RWBoolean b) const;
  219.  
  220.  
  221.      Returns TTTTRRRRUUUUEEEE if every bit of self is set to the boolean value bbbb.
  222.      Otherwise FFFFAAAALLLLSSSSEEEE.
  223.  
  224.               RWBoolean
  225.           ooooppppeeeerrrraaaattttoooorrrr!!!!====(RWBoolean b) const;
  226.  
  227.  
  228.      Returns FFFFAAAALLLLSSSSEEEE if every bit of self is set to the boolean value bbbb.
  229.      Otherwise TTTTRRRRUUUUEEEE.
  230.  
  231. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  232.               void
  233.           cccclllleeeeaaaarrrrBBBBiiiitttt(size_t i);
  234.  
  235.  
  236.      Clears (iiii....eeee...., sets to FFFFAAAALLLLSSSSEEEE) the bit with index iiii.  The index iiii must be
  237.      between 0 and the length of the vector less one.  No bounds checking is
  238.      performed.  The following are equivalent, although cccclllleeeeaaaarrrrBBBBiiiitttt((((ssssiiiizzzzeeee____tttt)))) is
  239.      slightly smaller and faster than using ooooppppeeeerrrraaaattttoooorrrr(((())))((((ssssiiiizzzzeeee____tttt)))):
  240.  
  241.                  a(i) = FALSE;
  242.  
  243.  
  244.  
  245.                  a.clearBit(i);
  246.  
  247.  
  248.  
  249.               const RWByte*
  250.           ddddaaaattttaaaa() const;
  251.  
  252.  
  253.      Returns a ccccoooonnnnsssstttt pointer to the raw data of self.  Should be used with
  254.      care.
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))                                                  RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))
  269.  
  270.  
  271.  
  272.               size_t
  273.           ffffiiiirrrrssssttttFFFFaaaallllsssseeee() const;
  274.  
  275.  
  276.      Returns the index of the first FFFFAAAALLLLSSSSEEEE bit in self.  Returns RRRRWWWW____NNNNPPPPOOOOSSSS if
  277.      there is no FFFFAAAALLLLSSSSEEEE bit.
  278.  
  279.               size_t
  280.           ffffiiiirrrrssssttttTTTTrrrruuuueeee() const;
  281.  
  282.  
  283.      Returns the index of the first TTTTRRRRUUUUEEEE bit in self.  Returns RRRRWWWW____NNNNPPPPOOOOSSSS if
  284.      there is no TTTTRRRRUUUUEEEE bit.
  285.  
  286.               unsigned
  287.           hhhhaaaasssshhhh() const;
  288.  
  289.  
  290.      Returns a value suitable for hashing.
  291.  
  292.               RWBoolean
  293.           iiiissssEEEEqqqquuuuaaaallll(const RWBitVec& v) const;
  294.  
  295.  
  296.      Returns TTTTRRRRUUUUEEEE if self and vvvv have the same length and if each bit of self
  297.      is set to the same value as the corresponding bit in vvvv.  Otherwise,
  298.      returns FFFFAAAALLLLSSSSEEEE.
  299.  
  300.               size_t
  301.           lllleeeennnnggggtttthhhh() const;
  302.  
  303.  
  304.      Returns the number of bits in the vector.
  305.  
  306.               ostream&
  307.           pppprrrriiiinnnnttttOOOOnnnn(ostream& s) const;
  308.  
  309.  
  310.      Print the vector vvvv on the output stream ssss.  See the example above for a
  311.      sample of the format.
  312.  
  313.               void
  314.           rrrreeeessssiiiizzzzeeee(size_t N);
  315.  
  316.  
  317.      Resizes the vector to have length NNNN.  If this results in a lengthening of
  318.      the vector, the additional bits will be set to FFFFAAAALLLLSSSSEEEE.
  319.  
  320.               istream&
  321.           ssssccccaaaannnnFFFFrrrroooommmm(istream&);
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))                                                  RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))
  335.  
  336.  
  337.  
  338.      Read the bit vector from the input stream ssss.  The vector will dynamically
  339.      be resized as necessary.  The vector should be in the same format printed
  340.      by member function pppprrrriiiinnnnttttOOOOnnnn((((oooossssttttrrrreeeeaaaammmm&&&&)))).
  341.  
  342.               void
  343.           sssseeeettttBBBBiiiitttt(size_t i);
  344.  
  345.  
  346.      Sets (iiii....eeee...., sets to TTTTRRRRUUUUEEEE) the bit with index iiii.  The index iiii must be
  347.      between 0 and ssssiiiizzzzeeee----1.  No bounds checking is performed.  The following
  348.      are equivalent, although sssseeeettttBBBBiiiitttt((((ssssiiiizzzzeeee____tttt)))) is slightly smaller and faster
  349.      than using ooooppppeeeerrrraaaattttoooorrrr(((())))((((ssssiiiizzzzeeee____tttt)))):
  350.  
  351.                  a(i) = TRUE;
  352.  
  353.  
  354.  
  355.                  a.setBit(i);
  356.  
  357.  
  358.  
  359.  
  360.               RWBoolean
  361.           tttteeeessssttttBBBBiiiitttt(size_t i) const;
  362.  
  363.  
  364.      Tests the bit with index iiii.  The index iiii must be between 0 and ssssiiiizzzzeeee----1.
  365.      No bounds checking is performed.  The following are equivalent, although
  366.      tttteeeessssttttBBBBiiiitttt((((ssssiiiizzzzeeee____tttt)))) is slightly smaller and faster than using
  367.      ooooppppeeeerrrraaaattttoooorrrr(((())))((((ssssiiiizzzzeeee____tttt)))):
  368.  
  369.                  if( a(i) )              doSomething();
  370.  
  371.  
  372.  
  373.                  if( a.testBit(i) )      doSomething();
  374.  
  375.  
  376.  
  377. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll FFFFuuuunnnnccccttttiiiioooonnnnssss
  378.               RWBitVec
  379.           ooooppppeeeerrrraaaattttoooorrrr!!!!(const RWBitVec& v);
  380.  
  381.  
  382.      Unary operator that returns the logical negation of vector vvvv.
  383.  
  384.               RWBitVec
  385.           ooooppppeeeerrrraaaattttoooorrrr&&&&(const RWBitVec&,const RWBitVec&);
  386.           RWBitVec
  387.           ooooppppeeeerrrraaaattttoooorrrr^^^^(const RWBitVec&,const RWBitVec&);
  388.           RWBitVec
  389.           ooooppppeeeerrrraaaattttoooorrrr||||(const RWBitVec&,const RWBitVec&);
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))                                                  RRRRWWWWBBBBiiiittttVVVVeeeecccc((((3333CCCC++++++++))))
  401.  
  402.  
  403.  
  404.      Returns a vector that is the logical AAAANNNNDDDD, XXXXOOOORRRR, or OOOORRRR of the vectors vvvv1111
  405.      and vvvv2222.  The two vectors must have the same length or an exception of
  406.      type RRRRWWWWIIIInnnntttteeeerrrrnnnnaaaallllEEEErrrrrrrr will occur.
  407.  
  408.               ostream&
  409.           ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(ostream& s, const RWBitVec& v);
  410.  
  411.  
  412.      Calls vvvv....pppprrrriiiinnnnttttOOOOnnnn((((ssss)))).
  413.  
  414.               istream&
  415.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(istream& s, RWBitVec& v);
  416.  
  417.  
  418.      Calls vvvv....ssssccccaaaannnnFFFFrrrroooommmm((((ssss)))).
  419.  
  420.               RWvostream&
  421.           ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream&, const RWBitVec& vec);
  422.           RWFile&
  423.           ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile&,     const RWBitVec& vec);
  424.  
  425.  
  426.      Saves the RRRRWWWWBBBBiiiittttVVVVeeeecccc vvvveeeecccc to a virtual stream or RRRRWWWWFFFFiiiilllleeee, respectively.
  427.  
  428.               RWvistream&
  429.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream&, RWBitVec& vec);
  430.           RWFile&
  431.           ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile&,     RWBitVec& vec);
  432.  
  433.  
  434.      Restores an RRRRWWWWBBBBiiiittttVVVVeeeecccc into vvvveeeecccc from a virtual stream or RRRRWWWWFFFFiiiilllleeee,
  435.      respectively, replacing the previous contents of vvvveeeecccc.
  436.  
  437.               size_t
  438.           ssssuuuummmm(const RWBitVec& v);
  439.  
  440.  
  441.      Returns the total number of bits set in the vector vvvv.
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.